#include<iostream>
#include<thread>
#include<mutex>
#include<condition_variable>
#include<list>

class ThreadPool
{
public:
    struct WORKS
    {
        pthread_t pthid;
        bool terminate;
        bool isrunning;
        ThreadPool* pool;
    }*thread_list;
    struct JOBS
    {
        void(*func)(void* args);
        void *user_data;
    };
public:
    ThreadPool(int numWorks,int _max_jobs);
    ~ThreadPool();
    void PushJob(void(*f)(void*arg),void* arg,int len);
private:
    void _addJob(JOBS* job);
    static void* _run(void* arg);
    void threadLoop(void* arg);
private:
    std::list<JOBS*> jobs_list;
    int max_jobs;
    int sum_thread;
    int free_thread;
    pthread_cond_t cond_jobs;
    pthread_mutex_t mutex;
};
